﻿﻿/* =====================================================================================================================
  * Author - Sachin Sharma
  * Copyright (c) 2012 Sachin Sharma (3screator.com). All rights reserved.
  * Follows most coding rules. However, due to time constraint you will see some hard coding or rules not strictly followed
=====================================================================================================================*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace SpellCheckeCS
{
    /// <summary>
    /// A basic page that provides characteristics common to most applications.
    /// </summary>
    public sealed partial class MainPage : SpellCheckeCS.Common.LayoutAwarePage
    {
        SpellCheckerViewModel _spellCheckerViewModel = null;
        public MainPage()
        {
            this.InitializeComponent();
            _spellCheckerViewModel = new SpellCheckerViewModel();
        }

       
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            
        }

  
        protected override void SaveState(Dictionary<String, Object> pageState)
        {
        }

        private void ButtonClick_SupportedLanguages(object sender, RoutedEventArgs e)
        {
            try
            {
                IList<string> lstLanguages = null;
                if (true == SpellCheckerWinRTComponent.SpellChecker.GetSpellChecker().GetSupportedLanguages(out lstLanguages))
                {
                    _spellCheckerViewModel.LanguageTags = new List<SpellCheckerSupportedLangs>();
                    foreach (string tag in lstLanguages)
                    {
                        _spellCheckerViewModel.LanguageTags.Add(new SpellCheckerSupportedLangs { LangTag = tag });
                    }
                    this.DataContext = null;
                    this.DataContext = _spellCheckerViewModel;
                }
            }
            catch (Exception ex)
            {
                SpellChecker.Core.SpellCheckerUtils.LogException(ex);
            }
        }

        private void ButtonClick_CheckSpelling(object sender, RoutedEventArgs e)
        {
            try
            {
                _spellCheckerViewModel.SpellCheckingResults = SpellCheckerWinRTComponent.SpellChecker.GetSpellChecker().CheckWordSpelling(textWord.Text.Trim(), "en-US"/*Pass language Tag*/);
                this.DataContext = null;
                this.DataContext = _spellCheckerViewModel;
            }
            catch (Exception ex)
            {
                SpellChecker.Core.SpellCheckerUtils.LogException(ex);
            }
        }

        private void textWord_GotFocus(object sender, RoutedEventArgs e)
        {
            if (textWord.Text == "Word Here")
                textWord.Text = string.Empty;
        }
    }
}
